home *** CD-ROM | disk | FTP | other *** search
/ PC Answers 2003 September / PC Answers September 2003.iso / Software / trial / MonitorIT 5.2.06 / monitorit_fullsetup.exe / data1.cab / Js / CalendarTimeFunc.js < prev    next >
Encoding:
JavaScript  |  2003-06-24  |  6.9 KB  |  203 lines

  1. /* ======================================================================
  2. DESC: Common Calendar Functions 
  3.  
  4. PLATFORMS: >= MS IE 4.0
  5. USAGE NOTES: 
  6. ====================================================================== */
  7. var   dowArray = new Array("Sun","Mon","Tue","Wed","Thu","Fri","Sat");
  8. var   baseDay = null;
  9. var    baseMonth = null;
  10. var    baseYear = null;
  11. var   baseDow = null;
  12. var   baseTime = null;
  13. var   curMonth = null;
  14. var    curYear = null;
  15. var    curSelMonth = null;
  16. var    curSelYear = null;
  17. var    curDay = null;
  18. var   UTxtArray = new Array("Minute(s) ","Hour(s)","Day(s)","Week(s)");
  19. var     UValArray = new Array(60000,3600000,86400000,604800000);
  20. var    cHrs = 0; // specified hours
  21. var    cMins = 0; // specified minutes
  22. var    cSecs = 0; // specified seconds
  23. var   selTime = null;
  24.  
  25. /* Initialize Calendar Function */
  26. function Calendar_init(CName,mode){
  27.     _param_ = new Object();
  28.     _param_.name = CName;
  29.     _param_.width = "215";
  30.     _param_.height = "230";
  31.     _param_.selDate = "";
  32.     _param_.wdayFormat = "FirstLetter";
  33.     _param_.textFont = "";
  34.     _param_.textSize = "";
  35.     _param_.textColor = "";
  36.     _param_.selColor = "lightgrey";
  37.     _param_.border = "0";
  38.     _param_.testMode = "off";
  39.     if ( arguments.length == 2 ) {
  40.             _param_.dirMode = mode;
  41.     }
  42.     else {
  43.             _param_.dirMode = null;
  44.     }
  45.     co = new com_netobjects_Calendar(_param_);
  46.     return co;
  47. }
  48.  
  49. /* Event Handler for Calendar Date/Month change */
  50. function processSelDate(selMonth, selDay, selYear, DFobj, dirMode) {
  51.     /* Verify the selection */
  52.     if ( selMonth < baseMonth && selYear == baseYear && dirMode == false) {
  53.         return false; // earlier than base month not allowed
  54.     }
  55.     else if ( selMonth > baseMonth && selYear == baseYear && dirMode == true) {
  56.         return false; // later than base month not allowed
  57.     }
  58.     if ( selMonth != curMonth ) { // New month selected
  59.         curMonth = selMonth; // set new month
  60.         curYear    = selYear;
  61.         return true; // render new month
  62.     } 
  63.     if ( selDay < baseDay && selMonth == baseMonth && dirMode == false ) {
  64.         return false; // earlier day then base day not allowed
  65.     }
  66.     if ( selDay > baseDay && selMonth == baseMonth && dirMode == true ) {
  67.         return false; // later day then base day not allowed
  68.     }
  69.     
  70.     /* New valid date selected */
  71.     curDay = selDay; // save it
  72.     dOb = new Date(selYear,selMonth,selDay); // selected date
  73.     dow = dOb.getDay(); //  determine day of week 
  74.     selTime = dOb.getTime(); // determine msecs since 1/1/70
  75.     
  76.     /* Update the Date field */
  77.     DFobj.value = " " + dowArray[dow] + "  " + DFobj.CalObj.getSelDate();
  78.     processCalendarClick(DFobj); // close calendar
  79.     checkEnableSchedButton(); // Enable Schedule Button?
  80.     return false; // no rendering
  81. }
  82.  
  83. /* Process Click on Start Date Field */
  84. function processCalendarClick(DFobj) {
  85.     if ( DFobj.className == "idis" ) {
  86.        return;
  87.     }
  88.     calname = DFobj.calendar;
  89.     if ( document.all[calname].CalState == "0" ) { // if closed
  90.         getTodayDate();
  91.         document.all[calname].CalState = "1"; // opened
  92.           document.all[calname].innerHTML = "";
  93.         document.all[calname].style.display="";
  94.         DFobj.CalObj.textSize = 2;
  95.         DFobj.CalObj.open(DFobj);
  96.         DFobj.CalObj.onSelDate = processSelDate; // set event handler
  97.         curSelMonth = curMonth = DFobj.CalObj.curMonth; // current Month and Year displayed
  98.         curSelYear = curYear = DFobj.CalObj.curYear;
  99.         curDay = DFobj.CalObj.curDay;
  100.     }
  101.     else {
  102.        document.all[calname].CalState = "0"; // closed
  103.        document.all[calname].style.display="none";
  104.     }
  105. }
  106.  
  107. /* Display Time Specified in cHrs, cMins, cSecs */
  108. function displaySpecifiedTime(fn) {
  109.         cM = (cHrs > 11) ? "PM" : "AM";
  110.         CH = (cHrs > 11) ? cHrs-12 : cHrs;
  111.         CH = (CH == 0) ? 12 : CH;
  112.         cMins = (cMins < 10) ? "0"+cMins : cMins;
  113.         cSecs = (cSecs < 10) ? "0"+cSecs : cSecs;
  114.         CH = (CH < 10) ? " "+CH : CH;
  115.         document.all[fn].value = " " + CH + ":" + cMins + " " + cM;
  116. }
  117.  
  118. /* Process Click on Time Field */
  119. function processTimeClick(Tpre,Tfn) {
  120.     if ( document.all[Tfn].TimeState == "0" ) { // TimeState, if closed
  121.         if ( document.all[Tfn].className == "idis" ) {
  122.             return; // ignore open if disabled
  123.        }
  124.         if (document.all[Tfn].value == "") getTodayDate();
  125.        document.all[Tfn].TimeState = "1"; // opened
  126.        document.all[Tpre+"_TimHrs"].style.display="";
  127.        document.all[Tpre+'_TempColon'].style.display="";
  128.        document.all[Tpre+"_TimMins"].style.display="";
  129.        document.all[Tpre+"_M"].style.display="";
  130.        document.all[Tpre+"_closebutton"].style.display = "";
  131.        //document.all[Tfn].style.display = "none";
  132.        document.all[Tfn].size = "1";
  133.        document.all[Tfn].value = "";
  134.          document.all[Tfn].className = "idis";
  135.       
  136.        CH = (cHrs > 12) ? cHrs-12 : cHrs;
  137.        CH = (CH == 0) ? 12 : CH;
  138.        document.all[Tpre+"_TimHrs"].options[--CH].selected = "selected";
  139.        document.all[Tpre+"_TimMins"].options[cMins].selected = "selected";
  140.        cM = (cHrs > 11 && cHrs < 24) ? 1 : 0;
  141.        document.all[Tpre+"_M"].options[cM].selected = "selected";
  142.        document.all[Tpre+"_TimHrs"].focus();
  143.     }
  144.     else {
  145.        document.all[Tfn].TimeState = "0"; // closed
  146.        cHrs = document.all[Tpre+"_TimHrs"].selectedIndex+1; // get selected option
  147.        cHrs = (cHrs == 12) ? 0 : cHrs; // Hr between 0 and 11
  148.         cMins = document.all[Tpre+"_TimMins"].selectedIndex;
  149.         cSecs = 0;
  150.         if ( (i = document.all[Tpre+"_M"].selectedIndex) == 1) //PM selected
  151.             cHrs += 12; // adjust hours
  152.         displaySpecifiedTime(Tfn);
  153.  
  154.        document.all[Tpre+'_TempColon'].style.display="none";
  155.        document.all[Tpre+"_TimHrs"].style.display="none";
  156.        document.all[Tpre+"_TimMins"].style.display="none";
  157.        document.all[Tpre+"_TimSecs"].style.display="none";
  158.        document.all[Tpre+"_M"].style.display="none";
  159.         document.all[Tpre+"_closebutton"].style.display = "none";
  160.        //document.all[Tfn].style.display = "";
  161.        document.all[Tfn].size = "10";
  162.          document.all[Tfn].className = "";
  163.       }
  164.       checkEnableSchedButton(); // Enable Schedule Button?
  165. }
  166.  
  167. function CreatTimeDropDowns(DDpre) {
  168.     /* Create and Display Start Time dropdown selections */
  169.     getTodayDate();
  170.     dct = document.all[DDpre+"_TimHrs"];
  171.     if ( dct.length == 0 ) { // if not defined yet
  172.        for ( var i=1; i<=12; i++ ) { // Hrs drop down
  173.             i = ( i < 10 ) ? " "+i : i;
  174.             addElementToSelect(dct," "+i);
  175.         }
  176.         dct = document.all[DDpre+"_TimMins"];
  177.         for ( i=0; i<=59; i++ ) { // Mins drop down
  178.             i = ( i < 10 ) ? "0"+i : i;
  179.             addElementToSelect(dct," "+i);
  180.         }
  181.         dct = document.all[DDpre+"_M"];
  182.         addElementToSelect(dct,"AM");
  183.         addElementToSelect(dct,"PM");
  184.     }
  185. }
  186.     
  187. function getTodayDate() {
  188.     var dOb = new Date(); // today's date object
  189.     cHrs = dOb.getHours(); // current time
  190.     cMins = dOb.getMinutes();
  191.     cSecs = dOb.getSeconds();
  192.  
  193.     baseDow = (baseDow == null) ? dOb.getDay() : baseDow;
  194.     baseDay = (baseDay == null) ? dOb.getDate() : baseDay; // today's date
  195.     baseMonth = (baseMonth == null) ? dOb.getMonth() : baseMonth;
  196.     baseYear = (baseYear == null) ? dOb.getFullYear() : baseYear;
  197.     baseTime = dOb.getTime();
  198. }
  199.  
  200.  
  201.  
  202.  
  203.